<template>
	<view class="input-warrper">
		<button @click="submit()">提交</button>
		<h3 style="margin:30rpx 0;">患者信息</h3>
		<div class="input-item">
			<label for=""><span class="colorRed">*</span> 患者姓名</label>
			<input v-model="form.patient_name" type="text" name="" id="" />
		</div>
		<div class="input-item">
			<label for=""><span class="colorRed">*</span> 性别<span style="opacity:0;">占位</span></label>
			<label class="radio" style="margin-left: 15rpx;">
				<radio-group @change="radio1change" ref="radio1" v-model="form.patient_gender_data">
					<radio value="1" /><text>男</text>
					<radio style="margin-left: 50rpx;" value="0" /><text>女</text>
				</radio-group>
			</label>
		</div>
		<div class="input-item">
			<label for=""><span class="colorRed">*</span> 年龄<span style="opacity:0;">占位</span></label>
			<input v-model="form.patient_age" type="number" name="" id="" />
		</div>
		
		<div class="input-item">
			<label for=""><span class="colorRed">*</span> 联系方式</label>
			<input v-model="form.patient_phone" type="number" name="" id="" />
		</div>
		
		<div class="input-item">
			<label for=""><span style="opacity: 0;">*</span> 联系人<span style="opacity:0;">占</span></label>
			<input v-model="form.patient_contacts" type="text" name="" id="" />
		</div>
		
		<h3 style="margin:30rpx 0;">病历信息</h3>
		<div class="input-item">
			<label for=""><span class="colorRed">*</span> 主要诊断</label>
			<input v-model="form.referral_diagnosis" type="text" name="" id="" />
		</div>
		<div class="input-item">
			<label for=""><span class="colorRed">*</span> 病情等级</label>
			<label class="radio">
				<!-- referral_urgency_data -->
				<radio-group @change="radio2change" ref="radio2" v-model="form.referral_urgency_data" name="">
					<radio style="margin-left: 30rpx;" value="1" /><text>一般</text>
					<radio style="margin-left: 40rpx;" value="2" /><text>病重</text>
					<radio style="margin-left: 40rpx;" value="3" /><text>复杂</text>
				</radio-group>
			</label>
		</div>
		<div class="input-item">
			<label for=""><span class="colorRed" style="opacity: 0;">*</span> 病情描述</label>
			<input v-model="form.referral_disease_desc" type="text" name="" id="" />
		</div>
		<image v-if="form.referral_disease_desc_images" style="width:160rpx;" :src="form.referral_disease_desc_images" mode="widthFix"></image>
		<div class="file-box" @click="fileUpdata('referral_disease_desc_images')">
			+
		</div>
		<!-- referral_disease_desc_images -->
		<div class="input-item">
			<label for=""><span class="colorRed" style="opacity: 0;">*</span> 诊疗过程</label>
			<input v-model="form.referral_treatment_process" type="text" name="" id="" />
		</div>
		<image v-if="form.referral_treatment_process_images" style="width:160rpx;" :src="form.referral_treatment_process_images" mode="widthFix"></image>
		<div class="file-box" @click="fileUpdata('referral_treatment_process_images')">
			+
		</div>
		
		<div class="input-item">
			<label for=""><span class="colorRed">*</span> 转诊目的</label>
			<input v-model="form.referral_reason" type="text" name="" id="" />
		</div>
		<div class="input-item">
			<label for=""><span class="colorRed" style="opacity: 0;">*</span> 检查报告</label>
			<image v-if="form.inspection_report_images" style="width:160rpx;" :src="form.inspection_report_images" mode="heightFix"></image>
			<div class="file-box" style="margin-left: 20rpx!important;" @click="fileUpdata('inspection_report_images')">
				+
			</div>
		</div>
		<div class="input-item">
			<label for=""><span class="colorRed" style="opacity: 0;">*</span> 检验报告</label>
			<image v-if="form.inspectd_report_images" style="width:160rpx;" :src="form.inspectd_report_images" mode="heightFix"></image>
			<div class="file-box" style="margin-left: 20rpx!important;" @click="fileUpdata('inspectd_report_images')">
				+
			</div>
		</div>
		<div class="input-item">
			<label for=""><span class="colorRed" style="opacity: 0;">*</span> 其他<span style="opacity:0;">占位</span></label>
			<image v-if="form.additional_images" style="width:160rpx;" :src="form.additional_images" mode="heightFix"></image>
			<div class="file-box" style="margin-left: 20rpx!important;" @click="fileUpdata('additional_images')">
				+
			</div>
		</div>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
					patient_name:"",
					patient_gender_data:"1",
					patient_age:"",
					patient_phone:"",
					patient_contacts:"",
					referral_diagnosis:"",
					referral_urgency_data:"",
					referral_disease_desc:"",
					referral_disease_desc_images:"",
					referral_treatment_process:"",
					referral_treatment_process_images:"",
					referral_reason:"",
					inspection_report_images:"",
					inspectd_report_images:"",
					additional_images:"",
				},
				userInfo:{},
				token:""
			}
		},
		onLoad() {
			let that = this;
			uni.getStorage({
				key:"userInfo",
				success: function (res) {
					that.token = JSON.parse(res.data).token
				},
			})
		},
		methods: {
			radio1change(data){
				this.form.patient_gender_data = data.detail.value
			},
			radio2change(data){
				this.form.referral_urgency_data = data.detail.value
			},
			submit(){
				let that = this;
				uni.request({
					url:this.$apiUrl+'api/referral/apply',
					method:"POST",
					header:{'token':that.token},
					data:this.form
				}).then(res=>{
					console.log(res[1].data);
					if(res[1].data.code == 1){
						uni.showToast({
							title:"提交成功！"
						})
						uni.navigateTo({
							url:"/pages/referralDetails/referralDetails?id="+res[1].data.data.id
						})
					}else{
						uni.showToast({
							title:res[1].data.msg,
							icon:"none"
						})
					}
				})
			},
			fileUpdata(field){
				let that = this;
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url:this.$apiUrl+'api/common/upload', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							header:{'token':that.token},
							name: 'file',
							formData: {
								'user': 'test'
							},
							success: (uploadFileRes) => {
								that.form[field] = that.$apiUrl+JSON.parse(uploadFileRes.data).data.url;
							}
						});
					}
				});
			}
		}
	}
</script>

<style scoped>
input[type="text"],input[type="number"]{
	border: 1rpx solid #f0f0f0;
	height: 80rpx;
}
.file-box{
	width: 160rpx;
	height: 160rpx;
	line-height:150rpx;
	text-align: center;
	background: #f0f0f0;
	margin:20rpx;
	font-size: 50rpx;
	color: #999;
	display: inline-block;
}
.input-warrper{
	padding:16rpx;
}
.colorRed{
	color: red;
}
.input-item{
	display: flex;
	align-items: center;
	margin-top:30rpx;
}
.input-item input{
	width: calc(100% - 200rpx);
	margin-left:20rpx;
}
</style>
